package com.wxh.rsa;

/**
 * @ClassName: Program
 * @Description:
 * @Author wxh
 * @Date: 2020/5/9 17:39
 * @Version V1.0.0
 * @Since 1.8
 */
public class Program {
    public static void main(String[] args) throws Exception {
        KeyPair keyPair = KeyGenerator.generateKeyPair();

        KeyPair asnKeyPair = keyPair.toASNKeyPair();
        KeyPair xmlKeyPair = asnKeyPair.toXMLKeyPair();
        KeyPair pemKeyPair = xmlKeyPair.toPEMKeyPair();


        String publicKey = asnKeyPair.getPublicKey();
        String privateKey = asnKeyPair.getPrivateKey();


        KeyWorker privateWorker = new KeyWorker(privateKey, KeyFormat.ASN);
        KeyWorker publicWorker = new KeyWorker(publicKey, KeyFormat.ASN);

        System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好！世界")));
        System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好！中国")));


        privateWorker = new KeyWorker(xmlKeyPair.getPrivateKey(), KeyFormat.XML);
        publicWorker = new KeyWorker(xmlKeyPair.getPublicKey(), KeyFormat.XML);
//
//        System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好！世界")));
//        System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好！中国")));
//
//        System.out.print(privateWorker.decrypt(publicWorker.encrypt("你好！世界")));
//        System.out.print(publicWorker.decrypt(privateWorker.encrypt("你好！中国")));
//
//        privateWorker = new KeyWorker(pemKeyPair.getPrivateKey(), KeyFormat.PEM);
//        publicWorker = new KeyWorker(pemKeyPair.getPublicKey(), KeyFormat.PEM);
        System.out.println("--------XML 加密-------");
        System.out.println(publicWorker.encrypt("你好！世界"));

        System.out.println("--------XML 解密-------");
        System.out.println(privateWorker.encrypt("你好！中国"));


    }
}
